package com.youhp.spire.xls.myDemo.Formatting;
import java.awt.Color;

import com.spire.xls.ExcelVersion;
import com.spire.xls.HorizontalAlignType;
import com.spire.xls.VerticalAlignType;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
/**
 * 
* @ClassName: TextAlign 
* @Description: 文本居中设置
* @author youhp
* @date 2020年7月15日 下午2:12:53
 */
public class TextAlign {

    public static void main(String[] args) {
        //Create a workbook
        Workbook workbook = new Workbook();

        //Load the document from disk
        workbook.loadFromFile("data/TextAlign.xlsx");

        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);
        
        //文本垂直方向设置（蓝色字）
        //Set the vertical alignment to Top
        sheet.getCellRange("B1:C1").getCellStyle().getExcelFont().setColor(Color.BLUE);
        sheet.getCellRange("B1:C1").getCellStyle().setVerticalAlignment(VerticalAlignType.Top);
        
        //Set the vertical alignment to Center
        sheet.getCellRange("B2:C2").getCellStyle().getExcelFont().setColor(Color.GREEN);
        sheet.getCellRange("B2:C2").getCellStyle().setVerticalAlignment(VerticalAlignType.Center);

        //Set the vertical alignment to Bottom
        sheet.getCellRange("B3:C3").getCellStyle().getExcelFont().setColor(Color.cyan);
        sheet.getCellRange("B3:C3").getCellStyle().setVerticalAlignment(VerticalAlignType.Bottom);

        //文本水平方向设置
        //Set the horizontal alignment to General
        sheet.getCellRange("B4:C4").getCellStyle().getExcelFont().setColor(Color.BLACK);
        sheet.getCellRange("B4:C4").getCellStyle().setHorizontalAlignment(HorizontalAlignType.General);

        //Set the horizontal alignment to Left
        sheet.getCellRange("B5:C5").getCellStyle().getExcelFont().setColor(Color.DARK_GRAY);
        sheet.getCellRange("B5:C5").getCellStyle().setHorizontalAlignment(HorizontalAlignType.Left);

        //Set the horizontal alignment to Center
        sheet.getCellRange("B6:C6").getCellStyle().getExcelFont().setColor(Color.GRAY);
        sheet.getCellRange("B6:C6").getCellStyle().setHorizontalAlignment(HorizontalAlignType.Center);

        //Set the horizontal alignment to Right
        sheet.getCellRange("B7:C7").getCellStyle().getExcelFont().setColor(Color.LIGHT_GRAY);
        sheet.getCellRange("B7:C7").getCellStyle().setHorizontalAlignment(HorizontalAlignType.Right);

        //Set the rotation degree
        sheet.getCellRange("B8:C8").getCellStyle().getExcelFont().setColor(Color.MAGENTA);
        sheet.getCellRange("B8:C8").getCellStyle().setRotation((int) Math.toRadians(45));
        
        sheet.getCellRange("B9:C9").getCellStyle().getExcelFont().setColor(Color.ORANGE);
        sheet.getCellRange("B9:C9").getCellStyle().setRotation((int) Math.toRadians(90));

        //Set the row height of cell
        sheet.getCellRange("B8:C9").setRowHeight(60);

        //Save the result file
        workbook.saveToFile("output/TextAlign.xlsx", ExcelVersion.Version2010);
    }
}
